package com.hzlh.configuration.cas;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class UserLoginInterceptor implements HandlerInterceptor {
//    @Autowired
//    private StringRedisTemplate stringRedisTemplate;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
//        if ("options".equalsIgnoreCase(request.getMethod())) {// options请求放行
//            return true;
//        }
//        String pcToken = request.getHeader(Constants.PC_TOKEN);
//        if(StringUtils.isEmpty(pcToken)){
//            throw new GlobalException(ResponseCode.UN_LOGIN);
//        }
//        String userInfoStr = this.stringRedisTemplate.opsForValue().get(UserInfoUtil.PCUSERINFO + pcToken);
//        if(StringUtils.isEmpty(userInfoStr)){
//            throw new GlobalException(ResponseCode.UN_LOGIN);
//        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
